<template>
    <div>
        <Card dis-hover :bordered="false">
            <Button
                type="primary"
                class="ivu-mb-8"
                @click="openedit(-1)"
                v-hasC="{
                    name: 'v1-setting-promotion-add-promotion',
                    flag: 'v1/setting/promotion/add-promotion',
                }"
                >{{ text.add }}</Button
            >
            <Table :columns="columns" :data="data">
                <template slot="action" slot-scope="{ row }">
                    <a
                        @click="openedit(row)"
                        v-hasC="{
                            name: 'v1-setting-promotion-update',
                            flag: 'v1/setting/promotion/update',
                        }"
                        >{{ text.update }}</a
                    >
                    <Divider type="vertical" />
                    <a
                        @click="deledit(row)"
                        v-hasC="{
                            name: 'v1-setting-promotion-del',
                            flag: 'v1/setting/promotion/del',
                        }"
                        >{{ text.del }}</a
                    >
                </template>
            </Table>
            <Modal
                v-model="showedit"
                :title="edits ? text.add : text.update"
                @on-cancel="canceledit(modalname)"
            >
                <Form :ref="modalname" :model="params" :rules="rules">
                    <FormItem :label="text.label1" prop="promotion_plan_id">
                        <Input
                            type="textarea"
                            v-model="params.promotion_plan_id"
                            :autosize="{ minRows: 2, maxRows: 5 }"
                            :placeholder="text.placeholder1"
                        />
                    </FormItem>
                    <FormItem :label="text.label2" prop="ding_token">
                        <Input
                            type="textarea"
                            :autosize="{ minRows: 2, maxRows: 5 }"
                            v-model="params.ding_token"
                            :placeholder="text.placeholder2"
                        />
                    </FormItem>
                </Form>
                <div slot="footer">
                    <Button @click="canceledit(modalname)">{{
                        text.cancel
                    }}</Button>
                    <Button type="primary" @click="submitedit(modalname)">{{
                        text.sub
                    }}</Button>
                </div>
            </Modal>
        </Card>
    </div>
</template>
<script>
import {
    settingpromotionindex,
    settingpromotionadd,
    settingpromotionupdate,
    settingpromotiondel,
} from "@/api/hqapi/indexone";
import mixins from "@/mixins/mixins";
export default {
    mixins: [mixins],
    data() {
        return {
            modalname: "jgmodal",
            rules: {
                promotion_plan_id: [
                    { required: true, message: "请输入", trigger: "blur" },
                ],
                ding_token: [
                    { required: true, message: "请输入", trigger: "blur" },
                ],
            },
            text: {
                add: "新增",
                update: "编辑",
                del: "删除",
                cancel: "取消",
                sub: "确定",
                label1: "推广计划ID",
                label2: "钉钉机器人token",
                placeholder1: "推广计划id，多个请换行，一行一个",
                placeholder2: "钉钉提醒的机器人token",
            },
            params: { id: undefined, promotion_plan_id: "", ding_token: "" },
            columns: [
                {
                    title: "推广计划ID",
                    key: "promotion_plan_id",
                    tooltip: true,
                },
                {
                    title: "钉钉机器人token",
                    key: "ding_token",
                    tooltip: true,
                },
                {
                    title: "操作时间",
                    key: "handle_time",
                },
                {
                    title: "操作",
                    slot: "action",
                },
            ],
            data: [],
            deltext: {
                title: "删除提示",
                content: "是否确认要删除推广计划的钉钉提醒",
            },
        };
    },
    methods: {
        /* @函数功能: 初始化 */
        initial() {
            this.funaskData = settingpromotionindex;
            this.funupdate = settingpromotionupdate;
            this.funcreate = settingpromotionadd;
            this.fundelete = settingpromotiondel;
            this.askData();
        },
        /* @函数功能: 请求数据 */
        askDatas(res) {
            this.data = res;
        },
        paramscancel() {
            this.params = {
                id: undefined,
                promotion_plan_id: "",
                ding_token: "",
            };
        },
        paramsedit(row) {
            this.params = {
                id: row.id,
                promotion_plan_id: row.promotion_plan_id,
                ding_token: row.ding_token,
            };
        },
        paramssubmit() {
            // let params = JSON.parse(JSON.stringify(this.params));
            // params.promotion_plan_id = JSON.stringify(params.promotion_plan_id);
            // return params;
            return this.params;
        },
        deledit(row) {
            let params = { promotion_id: row.id };
            this.deleteedit(params, this.deltext);
        },
    },
};
</script>
